package com.spic.business.vehicle.carInfo.controller;

import com.alibaba.fastjson.JSONObject;
import com.spic.business.vehicle.carInfo.domain.CarInfoDto;
import com.spic.business.vehicle.carInfo.domain.CarParamDto;
import com.spic.business.vehicle.carInfo.service.CarInfoContext;
import com.spic.business.vehicle.carInfo.service.impl.ZYCLCarInfoServiceImpl;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : 赵祥
 * create at:  2022/11/4  17:16
 * @Description :
 **/
@RestController
@RequestMapping("/vehicle/car")
public class CarInfoController extends BaseController {
    @Autowired
    private ZYCLCarInfoServiceImpl zyclCarInfoService;

    @GetMapping("/list")
    public AjaxResult list(CarParamDto carParamDto) {
        CarInfoContext context = new CarInfoContext(carParamDto.getCarType());
        List<CarInfoDto> list = context.selectCarList();
        return AjaxResult.success(list);
    }

    @GetMapping("/getUserMarkers")
    public AjaxResult getUserMarkers(CarParamDto carParamDto) {
        CarInfoContext context = new CarInfoContext(carParamDto.getCarType());
        JSONObject jsonObject = context.getUserMarkers();
        return AjaxResult.success(jsonObject);
    }

    /**
     * 同步自有车辆的油耗到车辆表
     */
    @GetMapping("/syncOilWear")
    public AjaxResult syncOilWear() {
        zyclCarInfoService.syncOilWear();
        return AjaxResult.success();
    }

}
